# -*- coding: utf8 -*-

from numpy import zeros


def half(mat):
    src_size = mat.shape
    half_size = (src_size[0] // 2, src_size[1] // 2)
    dst = zeros(half_size)
    for i in range(half_size[0]):
        for j in range(half_size[1]):
            dst[i, j] = sum((mat[i * 2, j * 2], mat[i * 2 + 1, j * 2], mat[i * 2 + 1, j * 2 + 1], mat[i * 2, j * 2 + 1])) // 4
    return dst

